<?php
/**
 * Notes:
 * User: wudg <544038230@qq.com>
 * Date: 2025/10/21 12:09
 */

namespace App\Controller\Amount;


use App\Controller\ApiController;
use App\Request\Amount\GroupAccountRequest;
use App\Request\Amount\GroupAmountRequest;
use App\Request\Amount\GroupTypeRequest;
use App\Service\Amount\GroupService;
use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;

class GroupController extends ApiController
{

    #[Inject]
    protected GroupService $service;


    /**
     * 按类目分组
     * @param GroupAmountRequest $request
     * @return ResponseInterface
     */
    public function category(GroupAmountRequest $request)
    {
        $params = $request->validated();
        $responseData = $this->service->groupByCategory($params);
        return $this->responseOk($responseData);
    }


    /**
     * 按账册聚合
     * @param GroupAccountRequest $request
     * @return ResponseInterface
     */
    public function account(GroupAccountRequest $request)
    {
        $params = $request->validated();
        $responseData = $this->service->groupByAccount($params);
        return $this->responseOk($responseData);
    }

    /**
     * 按收入支出类型聚合
     * @param GroupTypeRequest $request
     * @return ResponseInterface
     */
    public function groupType(GroupTypeRequest $request)
    {
        $params = $request->validated();

        list($inAmount,$outAmount,$nowAmount) = $this->service->groupByType($params);
        return $this->responseOk([
            'in' => $inAmount,
            'out' => $outAmount,
            'now' => $nowAmount,
        ]);
    }
}